package com.aliang.chat.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.aliang.chat.enums.MessageTypeEnum;
import com.aliang.chat.enums.ResultCodeEnum;
import com.aliang.chat.model.Result;
import com.aliang.chat.model.dto.MessageDTO;
import com.aliang.chat.service.MessageService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {
    @Resource
    public MessageService messageService;

    @GetMapping("/list")
    public Result getMessageList(Integer userId, Integer contactId) {
        List<MessageDTO> messageList = messageService.getMessageList(userId, contactId);
        return Result.success(messageList);
    }

    @DeleteMapping("/delete")
    public Result deleteMessage(@RequestBody MessageDTO messageDTO) {
        if (BeanUtil.isEmpty(messageDTO)) {
            return Result.error(ResultCodeEnum.PARAM_ERROR);
        }
       boolean flag = messageService.delete(messageDTO);
        return flag ? Result.success() : Result.error();
    }
}
